import _ from 'underscore'
import dispatcher from 'lib/dispatcher'
import {Scope} from 'lib/scopeFactory'
import traceDetail from '../apis/traceDetail'

function parseTrace(data){
  return _.extend({},data,{
		params:JSON.parse(data.params),
		trace:data.trace.split('\n'),
		responseBody:data.responseBody
	});
}

export default class TraceScope extends Scope {
  constructor(props){
    super();
    this.traceId = props.routeParams.traceId
    this.$state = {
      errortrace:null
    }
    this.traceApi = traceDetail({
      id:this.traceId,
      urlName:'httperrortracedetail'
    })
  }
  fetch(){
    var _this = this
    this.traceApi.fetch().then(function(data,params){
      _this.$state.errortrace = parseTrace(data)
      _this.emit()
    })
  }
  $unload(){
  }
  $load(){
    var _this = this
    this.fetch();

  }
}
